//
//  RecordDetailVC.m
//  HengYouCai
//
//  Created by ycgwl on 2017/5/3.
//  Copyright © 2017年 lwj. All rights reserved.
//

#import "RecordDetailVC.h"
#import "BannerWebViewVC.h"
@interface RecordDetailVC ()

/**
 查看协议
 */
@property (weak, nonatomic) IBOutlet UIButton *protocolBtn;

/**
 项目详情
 */
@property (weak, nonatomic) IBOutlet UIButton *detailBtn;

@property (nonatomic, retain)NSMutableArray *titleArr;
@property (nonatomic, retain)NSDictionary *detailDic;
@end

@implementation RecordDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _protocolBtn.layer.borderColor = Normal_RedColor.CGColor;
    _detailBtn.layer.borderColor = Normal_RedColor.CGColor;
    
    _protocolBtn.hidden = [_status isEqualToString:@"2"];
    WLGetWeakSelf(weakSelf, self);
    [[_protocolBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [weakSelf.view showHUDLoading];
        [HYCNetService getProtocolInvestmentWithDict:@{@"id":_model.orderId} OnSuccess:^(NSDictionary *dictResult) {
            //
            [weakSelf.view hideHUDLoading:0];
            BannerWebViewVC *web = [[BannerWebViewVC alloc] initWithUrlStr:dictResult[@"url"] title:@"投资协议"];
            [weakSelf.navigationController pushViewController:web animated:YES withHideBottomBarWhenPush:YES pop:YES];
        } andFailed:^(NSInteger code, NSString *errorMsg) {
            //
            [weakSelf.view showHUDFailTips:errorMsg hideDelay:1.8];
        }];
        
        
    }];
    
    
}

#pragma tableviewDatasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.titleArr.count;
}
#pragma tableviewDelegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"recordDetailCellID"];
    UILabel *lab = [cell viewWithTag:1001];
    lab.text = _titleArr[indexPath.row];
    UILabel *detailLab = [cell viewWithTag:1002];
    
    if (_detailDic) {
        switch (indexPath.row) {
                // 投资金额
            case 0:
            {
                detailLab.text = _detailDic[@"amount"];
            }
                break;
                // 投资日期
            case 1:
            {
                detailLab.text = _detailDic[@"addTime"];
            }
                break;
                // 历史年化
            case 2:
            {
                detailLab.text = _detailDic[@"minProfit"];
            }
                break;
                // 投资期限
            case 3:
            {
                detailLab.text = _detailDic[@"plstimeLimit"];
            }
                break;
                // 加息券加息收益
            case 4:
            {
                detailLab.text = _detailDic[@"bonusesInterest"];
            }
                break;
                // 红包返现金额
            case 5:
            {
                detailLab.text = _detailDic[@"bonusesAmount"];
            }
                break;
                // 基本收益
            case 6:
            {
                detailLab.text = _detailDic[@"minInterest"];
            }
                break;
                // 预估总收益
            case 7:
            {
                detailLab.text = _detailDic[@"interestSum"];
            }
                break;
                // 回款日期
            case 8:
            {
                detailLab.text = _detailDic[@"endTime"];
            }
                break;
                // 目前状态
            case 9:
            {
                detailLab.text = _detailDic[@"showStatus"];
            }
                break;
            default:
                break;
        }
    }
    
    return cell;
}
- (NSMutableArray *)titleArr
{
    if (!_titleArr) {
        _titleArr = [NSMutableArray array];
//        self.titleArr = @[@"投资金额",@"投资日期",@"历史年化",@"投资期限",@"加息券收益",@"红包抵扣金额",@"基本收益",@"预估总收益",@"回款日期",@"目前状态"];
    }
    return _titleArr;
}
- (void)setModel:(InvestListModel *)model
{
    _model = model;
//    self.navigationItem.title = model.title;
    
    [HYCNetService myWalletInvestDetailInfoWithDict:@{@"orderId":model.orderId} onSuccess:^(NSDictionary *dictResult) {
        //
        self.detailDic = dictResult[@"investDetailInfo"];
        self.navigationItem.title = self.detailDic[@"title"];
        
        [self.titleArr addObject:self.detailDic[@"amountLabel"]];//投资金额
        [self.titleArr addObject:self.detailDic[@"addTimeLabel"]];//投资日期

        [self.titleArr addObject:self.detailDic[@"minProfitLabel"]];//历史年化
        [self.titleArr addObject:self.detailDic[@"addTimeLabel"]];//投资期限
        [self.titleArr addObject:self.detailDic[@"bonusesInterestLabel"]];//加息券收益
        [self.titleArr addObject:self.detailDic[@"bonusesAmountLabel"]];//红包抵扣金额
        [self.titleArr addObject:self.detailDic[@"minInterestLabel"]];//基本收益
        [self.titleArr addObject:self.detailDic[@"interestSumLabel"]];//预估总收益
        [self.titleArr addObject:self.detailDic[@"endTimeLabel"]];//回款日期
        [self.titleArr addObject:self.detailDic[@"showStatusLabel"]];//目前状态
        
        [self.tableView reloadData];
    } andFailed:^(NSInteger code, NSString *errorMsg) {
        //
    }];
}
@end

